<template>
  <el-container class='elheight'>
    <el-aside class='appTree'>
      <app-tree :tree-data="treeData" v-on:appTreeClick="appTreeClick"></app-tree>
    </el-aside>
    <el-main>
      <el-container>
        <el-header class="dzy-main-header">
          <div class="btn-group-el">
            <btn-group :currentSelectedData="currentSelectedData" @btnClickCallback="btnClickCallback"></btn-group>
          </div>
          <div class="dzy-custom-search-box">
            <div>
              名称：<el-input placeholder="请输入案件名称" v-model="selectForm.caseName" clearable class="dzy-custom-input"></el-input>
            </div>
            <div>
              编号：<el-input placeholder="请输入内容" v-model="selectForm.caseNo" clearable class="dzy-custom-input"></el-input>
            </div>
            <div>
              案件发生开始日期：
                <el-date-picker
                  v-model="selectForm.beginTime"
                  type="date"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="timestamp"
                  placeholder="选择日期"
                  :picker-options="dataPickerBeforeTodayOptions">
                </el-date-picker>
            </div>
            <div>
              案件发生结束日期：
                <el-date-picker
                  v-model="selectForm.endTime"
                  type="date"
                  value-format="timestamp"
                  format="yyyy 年 MM 月 dd 日"
                  placeholder="选择日期"
                  :picker-options="dataPickerBeforeTodayOptions">
                </el-date-picker>
            </div>
            <div>
              <el-button @click="searchHandleClick" type="primary" icon="el-icon-search">查询</el-button>
            </div>
          </div>
        </el-header>
        <el-main>
          <app-table
            :page-data="pageData"
            :table-columns="tableColumns"
            v-on:currentChange="handleCurrentChange"
            v-on:handleCheckedRows="handleCheckedRows"
            v-on:checkCriminalSuspect="checkCriminalSuspect"
            v-on:checkVictim="checkVictim">
          </app-table>
          <el-dialog title="" :visible.sync="dialogFormVisible" class="custom-dialog_style_twoLine" :before-close="cancel" :close-on-click-modal="false">
            <el-form :model="formData"
                     :rules="rules"
                     ref="formData"
                     :disabled="showOnly"
                     label-width="50%">
              <el-form-item label="名称：" prop="caseName" label-width="30%">
                <el-input v-model="formData.caseName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="编号：" prop="caseNo" label-width="30%">
                <el-input v-model="formData.caseNo" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="案件发生开始日期：" prop="beginTime" label-width="30%">
                <div class="block">
                  <el-date-picker
                    v-model="formData.beginTime"
                    type="date"
                    format="yyyy 年 MM 月 dd 日"
                    value-format="timestamp"
                    placeholder="选择日期"
                    :picker-options="dataPickerBeforeTodayOptions">
                  </el-date-picker>
                </div>
              </el-form-item>
              <el-form-item label="侦查终结日期：" prop="endTime" label-width="30%">
                <div class="block">
                  <el-date-picker
                    v-model="formData.endTime"
                    type="date"
                    value-format="timestamp"
                    format="yyyy 年 MM 月 dd 日"
                    placeholder="选择日期"
                    :picker-options="dataPickerBeforeTodayOptions">
                  </el-date-picker>
                </div>
              </el-form-item>
              <el-form-item label="简要情况：" label-width="30%" class="custom-textarea-container">
                <el-input type="textarea" v-model="formData.introduction"></el-input>
              </el-form-item>
              <el-form-item label="" label-width="30%">
              </el-form-item>
              <el-form-item label="街道/社区/网格：" prop="gridIdArr" label-width="30%">
                <div class="block">
                  <el-cascader
                    placeholder="请选择"
                    :options="treeData"
                    filterable
                    clearable
                    :props="gridIdProps"
                    v-model="formData.gridIdArr"
                    change-on-select>
                  </el-cascader>
                </div>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" v-if="isfooterBtnShow">
              <el-button @click="cancel">取 消</el-button>
              <el-button type="primary" @click="save('formData')">确 定</el-button>
            </div>
          </el-dialog>
          <el-dialog
            title="嫌疑人列表"
            :visible.sync="isCriminalSuspectTableShow"
            :before-close="cancel">
            <el-table
              :data="criminalSuspecTableData"
              style="width: 100%">
              <el-table-column
                v-for="(item, index) in criminalSuspecTableColumns"
                :key="index" :prop="item.prop"
                :label="item.label"
                :formatter="item.formatter">
              </el-table-column>
              <el-table-column label="">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    @click="checkCriminalSuspectDetail(scope.$index, criminalSuspecTableData)">查看详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-dialog>
          <el-dialog
            title="受害人列表"
            :visible.sync="isVictimTableShow"
            :before-close="cancel">
              <el-table
                :data="victimTableData"
                style="width: 100%">
                <el-table-column
                  v-for="(item, index) in victimTableColumns"
                  :key="index" :prop="item.prop"
                  :label="item.label"
                  :formatter="item.formatter">
                </el-table-column>
                <el-table-column label="">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      @click="checkVictimDetail(scope.$index, victimTableData)">查看详情</el-button>
                  </template>
                </el-table-column>
              </el-table>
          </el-dialog>
          <el-dialog :title="dialogTitle" :visible.sync="isVictimDialogShow" :before-close="criminalSuspectDialogCancel">
            <el-form :model="victimFormData" label-width="50%">
              <el-form-item label="案件编号：" label-width="30%">
                <el-input v-model="victimFormData.caseNumber" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="姓名：" label-width="30%">
                <el-input v-model="victimFormData.name" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="曾用名：" label-width="30%">
                <el-input v-model="victimFormData.usedName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="证件代码：" label-width="30%">
                <el-select v-model="victimFormData.credentialsCode" placeholder="请选择">
                  <el-option v-for="(item,index) in codeOptions" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="证件号码：" label-width="30%">
                <el-input v-model="victimFormData.credentialsNumber" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="性别：" label-width="30%">
                <el-select v-model="victimFormData.gender" placeholder="请选择">
                  <el-option v-for="(item,index) in genderOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="出生日期：" label-width="30%">
                <div class="block">
                  <el-date-picker
                    v-model="victimFormData.birthday"
                    type="date"
                    value-format="timestamp"
                    format="yyyy 年 MM 月 dd 日"
                    placeholder="选择日期"
                    :picker-options="dataPickerBeforeTodayOptions">
                  </el-date-picker>
                </div>
              </el-form-item>
              <el-form-item label="国籍（地区）：" label-width="30%">
                <el-select v-model="victimFormData.nationality" autocomplete="off" clearable filterable placeholder="请选择">
                  <el-option v-for="(item,index) in nationalityOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="民族：" label-width="30%">
                <el-select v-model="victimFormData.nation" clearable filterable placeholder="请选择">
                  <el-option v-for="(item,index) in nationOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="籍贯：" label-width="30%">
                <el-input v-model="victimFormData.birthplace" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="婚姻状况：" label-width="30%">
                <div class="block">
                  <el-cascader
                    v-model="victimFormData.victimMaritalStatusArr"
                    placeholder="请选择"
                    :options="maritalStatusOption"
                    filterable
                    :props="dictProps"
                    clearable
                    change-on-select>
                  </el-cascader>
                </div>
              </el-form-item>
              <el-form-item label="政治面貌：" label-width="30%">
                <el-select v-model="victimFormData.politicalStatus" clearable filterable placeholder="请选择">
                  <el-option v-for="(item,index) in politicalStatusOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="学历：" label-width="30%">
                <div class="block">
                  <el-cascader
                    v-model="victimFormData.victimEducationArr"
                    placeholder="请选择"
                    :options="educationOption"
                    filterable
                    :props="dictProps"
                    clearable
                    change-on-select>
                  </el-cascader>
                </div>
              </el-form-item>
              <el-form-item label="宗教信仰：" label-width="30%">
                <el-select v-model="victimFormData.religion" clearable filterable placeholder="请选择">
                  <el-option v-for="(item,index) in religionOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="职业类别：" label-width="30%">
                <el-select v-model="victimFormData.careerCategory" clearable placeholder="请选择">
                  <el-option v-for="(item,index) in careerCategoryOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="职业：" label-width="30%">
                <el-input v-model="victimFormData.career" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="服务处所：" label-width="30%">
                <el-input v-model="victimFormData.servicePlace" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="户籍地：" label-width="30%">
                <el-input v-model="victimFormData.householdAddr" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="户籍门(楼)详址：" label-width="30%">
                <el-input v-model="victimFormData.householdAddrDetail" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="现住地：" label-width="30%">
                <el-input v-model="victimFormData.currentAddr" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="现住门(楼)详址：" label-width="30%">
                <el-input v-model="victimFormData.currentAddrDetail" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="街道/社区/网格：" label-width="30%">
                <div class="block">
                  <el-cascader
                    placeholder="请选择"
                    :options="treeData"
                    filterable
                    clearable
                    :props="gridIdProps"
                    v-model="victimFormData.gridIdArr">
                  </el-cascader>
                </div>
              </el-form-item>
            </el-form>
          </el-dialog>
          <el-dialog
            :title="dialogTitle"
            :visible.sync="isCriminalSuspectDialogShow"
            class="custom-dialog_style_twoLine"
            :before-close="criminalSuspectDialogCancel"
            :close-on-click-modal="false">
            <el-form :model="criminalSuspectFormData" label-width="50%">
              <el-form-item label="案件编号：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.caseNumber" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="姓名：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.name" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="曾用名：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.usedName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="证件代码：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.credentialsCode" placeholder="请选择">
                  <el-option v-for="(item,index) in codeOptions" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="证件号码：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.credentialsNumber" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="性别：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.gender" placeholder="请选择">
                  <el-option v-for="(item,index) in genderOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="出生日期：" label-width="30%">
                <div class="block">
                  <el-date-picker
                    v-model="criminalSuspectFormData.birthday"
                    type="date"
                    value-format="timestamp"
                    format="yyyy 年 MM 月 dd 日"
                    placeholder="选择日期"
                    :picker-options="dataPickerBeforeTodayOptions">
                  </el-date-picker>
                </div>
              </el-form-item>
              <el-form-item label="国籍（地区）：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.nationality" autocomplete="off" clearable filterable placeholder="请选择">
                  <el-option v-for="(item,index) in nationalityOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="民族：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.nation" clearable placeholder="请选择">
                  <el-option v-for="(item,index) in nationOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="籍贯：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.birthplace" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="婚姻状况：" label-width="30%">
                <div class="block">
                  <el-cascader
                    v-model="criminalSuspectFormData.criminalSuspectMaritalStatusArr"
                    placeholder="请选择"
                    :options="maritalStatusOption"
                    filterable
                    :props="dictProps"
                    clearable
                    change-on-select>
                  </el-cascader>
                </div>
              </el-form-item>
              <el-form-item label="政治面貌：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.politicalStatus" clearable filterable placeholder="请选择">
                  <el-option v-for="(item,index) in politicalStatusOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="学历：" label-width="30%">
                <div class="block">
                  <el-cascader
                    v-model="criminalSuspectFormData.criminalSuspectEducationArr"
                    placeholder="请选择"
                    :options="educationOption"
                    filterable
                    :props="dictProps"
                    clearable
                    change-on-select>
                  </el-cascader>
                </div>
                <el-select v-model="criminalSuspectFormData.education" clearable placeholder="请选择">
                  <el-option v-for="(item,index) in educationOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="宗教信仰：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.religion" clearable placeholder="请选择">
                  <el-option v-for="(item,index) in religionOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="职业类别：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.careerCategory" clearable placeholder="请选择">
                  <el-option v-for="(item,index) in careerCategoryOption" :key="index" :label="item.name" :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="职业：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.career" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="服务处所：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.servicePlace" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="户籍地：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.householdAddr" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="户籍门(楼)详址：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.householdAddrDetail" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="现住地：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.currentAddr" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="现住门(楼)详址：" label-width="30%">
                <el-input v-model="criminalSuspectFormData.currentAddrDetail" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="是否为严重精神病障碍患者：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.isMental" clearable placeholder="请选择">
                  <el-option label="否" :value="0"></el-option>
                  <el-option label="是" :value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="是否为未成年：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.isMinor" clearable placeholder="请选择">
                  <el-option label="否" :value="0"></el-option>
                  <el-option label="是" :value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="是否为青少年：" label-width="30%">
                <el-select v-model="criminalSuspectFormData.isTeens" clearable placeholder="请选择">
                  <el-option label="否" :value="0"></el-option>
                  <el-option label="是" :value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="街道/社区/网格：" label-width="30%">
                <div class="block">
                  <el-cascader
                    placeholder="请选择"
                    :options="treeData"
                    filterable
                    clearable
                    :props="gridIdProps"
                    v-model="criminalSuspectFormData.gridIdArr">
                  </el-cascader>
                </div>
              </el-form-item>
            </el-form>
          </el-dialog>
        </el-main>
      </el-container>
    </el-main>
  </el-container>
</template>

<script>
import AppTree from '@/components/common/AppTree'
import AppTable from '@/components/AppTable'
import BtnGroup from '@/components/BtnGroup'
import {getAllRegion} from '@/utils/region'
import {getUserGridTree} from '@/utils/SessionDataUtil'
import {getDictDataOption} from '@/utils/getDictDataOption'
import {getHomicide, createHomicide, updateHomicide, delHomicide, getHomicideSuspect, getVictim} from '@/http/PublicSecurityAppApi'
export default {
  data () {
    return {
      isfooterBtnShow: true,
      isVictimTableShow: false,
      isVictimDialogShow: false,
      isCriminalSuspectTableShow: false,
      isCriminalSuspectDialogShow: false,
      dialogFormVisible: false,
      treeData: [],
      pageData: {},
      dialogTitle: '',
      currentSelectedData: [],
      showOnly: false,
      tableColumns: [
        { prop: 'caseName', label: '名称', width: '120' },
        { prop: 'caseNo', label: '编号', width: '80' },
        { prop: 'beginTime', label: '案件发生开始日期', formatter: this.dateFormatter },
        { prop: 'endTime', label: '侦察终结日期', formatter: this.dateFormatter }
      ],
      criminalSuspecTableColumns: [
        { prop: 'name', label: '姓名' },
        { prop: 'credentialsNumber', label: '证件号' },
        { prop: 'gender', label: '性别', formatter: this.genderFormatter, width: '50' }
      ],
      victimTableColumns: [
        { prop: 'name', label: '姓名' },
        { prop: 'credentialsNumber', label: '证件号' },
        { prop: 'gender', label: '性别', formatter: this.genderFormatter, width: '50' }
      ],
      dataPickerBeforeTodayOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      victimTableData: [],
      criminalSuspecTableData: [],
      tableDada: [],
      formData: {},
      selectForm: {},
      victimFormData: {},
      criminalSuspectFormData: {},
      gridIdProps: {
        label: 'name',
        value: 'id'
      },
      dictProps: {
        label: 'name',
        value: 'code'
      },
      rules: {
        caseName: [
          { required: true, message: '请输入事件名称：', trigger: 'blur' }
        ],
        caseNo: [
          { required: true, message: '请输入事件编号', trigger: 'blur' }
        ],
        beginTime: [
          { required: true, message: '请选择开始实时间', trigger: 'blur' }
        ],
        endTime: [
          { required: true, message: '请选择结束时间', trigger: 'blur' }
        ],
        gridIdArr: [
          { required: true, message: '请选择网格', trigger: 'blur' }
        ]
      },
      codeOptions: [],
      nationalityOption: [],
      genderOption: [],
      nationOption: [],
      maritalStatusOption: [],
      politicalStatusOption: [],
      educationOption: [],
      religionOption: [],
      careerCategoryOption: []
    }
  },
  components: {
    AppTree,
    BtnGroup,
    AppTable
  },
  mounted () {
    this.getTreeData()
    this.getTableData()
    this.getDictData()
  },
  methods: {
    // 格式化性别
    genderFormatter (row, column) {
      let genderOption = getDictDataOption('性别')
      let resGender = ''
      for (let i = 0; i < genderOption.length; i++) {
        if (genderOption[i].code === row.gender) {
          resGender = genderOption[i].name
          break
        }
      }
      return resGender
    },
    // 格式化时间戳
    dateFormatter (row, column) {
      let prop = column.property
      let resTime = row[prop]
      if (!resTime || resTime === '') return ''
      return this.$moment(resTime).format('YYYY-MM-DD')
    },
    // 查看受害人详情
    checkVictimDetail (index, data) {
      this.victimFormData = data[index]
      let gridIdArr = this.victimFormData.allGridId.split(',')
      this.victimFormData.victimMaritalStatusArr = this.victimFormData.maritalStatus !== '' && this.victimFormData.maritalStatus !== null ? this.victimFormData.maritalStatus.split(',') : []
      this.victimFormData.victimEducationArr = this.victimFormData.education !== '' && this.victimFormData.education !== null ? this.victimFormData.education.split(',') : []
      let arr = []
      arr.push(gridIdArr[2])
      arr.push(gridIdArr[3])
      arr.push(gridIdArr[4])
      this.isVictimDialogShow = true
      this.victimFormData.gridIdArr = arr
    },
    // 查看嫌疑人详情
    checkCriminalSuspectDetail (index, data) {
      this.criminalSuspectFormData = data[index]
      let gridIdArr = this.criminalSuspectFormData.allGridId.split(',')
      this.criminalSuspectFormData.criminalSuspectMaritalStatusArr = this.criminalSuspectFormData.maritalStatus !== '' && this.criminalSuspectFormData.maritalStatus !== null ? this.criminalSuspectFormData.maritalStatus.split(',') : []
      this.criminalSuspectFormData.criminalSuspectEducationArr = this.criminalSuspectFormData.education !== '' && this.criminalSuspectFormData.education !== null ? this.criminalSuspectFormData.education.split(',') : []
      let arr = []
      arr.push(gridIdArr[2])
      arr.push(gridIdArr[3])
      arr.push(gridIdArr[4])
      this.isCriminalSuspectDialogShow = true
      this.criminalSuspectFormData.gridIdArr = arr
    },
    // 查看嫌疑人
    checkCriminalSuspect (data) {
      let caseNo = data.data[data.index].caseNo
      let param = {
        caseNumber: caseNo
      }
      let m = this
      getHomicideSuspect(param).then(resp => {
        if (resp.code && resp.code === '200') {
          if (resp.data.total === 0) {
            m.$message({
              type: 'info',
              message: '无嫌疑人信息'
            })
            return ''
          }
          m.criminalSuspecTableData = resp.data.items
          m.isCriminalSuspectTableShow = true
        } else {
          m.$message({
            type: 'info',
            message: resp.message
          })
          return ''
        }
      })
    },
    // 查看受害人
    checkVictim (data) {
      let caseNo = data.data[data.index].caseNo
      let param = {
        caseNumber: caseNo
      }
      var m = this
      getVictim(param).then(resp => {
        if (resp.code && resp.code === '200') {
          if (resp.data.total === 0) {
            m.$message({
              type: 'info',
              message: '无受害人信息'
            })
            return ''
          }
          m.victimTableData = resp.data.items
          m.isVictimTableShow = true
        } else {
          m.$message({
            type: 'info',
            message: resp.message
          })
          return ''
        }
      })
    },
    getTreeData () {
      let data = getUserGridTree()
      if (data && data instanceof Array) {
        this.treeData = data
      }
    },
    getDictData () {
      this.codeOptions = getDictDataOption('证件代码')
      this.nationalityOption = getDictDataOption('国家和地区')
      this.genderOption = getDictDataOption('性别')
      this.nationOption = getDictDataOption('民族')
      this.maritalStatusOption = getDictDataOption('婚姻状况')
      this.politicalStatusOption = getDictDataOption('政治面貌')
      this.educationOption = getDictDataOption('学历')
      this.religionOption = getDictDataOption('宗教信仰')
      this.careerCategoryOption = getDictDataOption('职业分类')
    },
    save (formName) {
      this.$refs[formName].validate((valid) => {
        if (!valid) {
          this.$alert('请填写正确表单格式', '', {
            confirmButtonText: '确定'
          })
          return ''
        } else {
          if (this.formData.gridIdArr && this.formData.gridIdArr !== 0) {
            let index = this.formData.gridIdArr.length - 1
            let data = {}
            data.id = this.formData.gridIdArr[index]
            data.items = this.treeData
            data.isGetAllId = true
            this.formData.allGridId = getAllRegion(data)
          } else {
            this.formData.allGridId = ''
          }
          if (this.formData.id) {
            updateHomicide(this.formData).then(resp => {
              if (resp.code && resp.code === '200') {
                this.dialogFormVisible = false
                this.$message({
                  type: 'success',
                  message: '修改成功'
                })
                this.getTableData()
              } else {
                this.$message({
                  type: 'info',
                  message: '修改失败'
                })
                return ''
              }
            })
          } else {
            createHomicide(this.formData).then(resp => {
              if (resp.code && resp.code === '200') {
                this.dialogFormVisible = false
                this.$message({
                  type: 'success',
                  message: '添加成功'
                })
                this.getTableData()
              } else {
                this.$message({
                  type: 'info',
                  message: '添加失败'
                })
                return ''
              }
            })
          }
        }
      })
    },
    del (rows) {
      if (rows && rows instanceof Array && rows.length > 0) {
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          rows.forEach(row => {
            delHomicide(row).then(resp => {
              if (resp.code && resp.code === '200') {
                this.$message({
                  type: 'success',
                  message: '删除成功'
                })
                this.getTableData()
              } else {
                this.$message({
                  type: 'info',
                  message: '删除失败'
                })
                return ''
              }
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    cancel () {
      this.dialogFormVisible = false
      this.isCriminalSuspectTableShow = false
      this.isVictimTableShow = false
      this.formData = {}
    },
    criminalSuspectDialogCancel () {
      this.isVictimDialogShow = false
      this.isCriminalSuspectDialogShow = false
      this.victimFormData = {}
      this.criminalSuspectFormData = {}
    },
    getTableData (param) {
      getHomicide(param).then(resp => {
        if (resp.code && resp.code === '200') {
          this.pageData = resp.data
          this.pageData.isShowoPerationCol = true
          if (this.pageData.items && this.pageData.items instanceof Array) {
            this.tableData = this.pageData.items
          }
        } else {
          this.$message({
            type: 'info',
            message: resp.message
          })
          return ''
        }
      })
    },
    handleCurrentChange (val) {
      this.selectForm.offset = (val - 1) * 10
      this.getTableData(this.selectForm)
    },
    btnClickCallback (callbackData) {
      if (callbackData.btnType === 'delete') {
        this.dialogFormVisible = false
        let rows = callbackData.rows
        this.del(rows)
      } else {
        this.isfooterBtnShow = callbackData.btnType !== 'get'
        if (callbackData.btnType === 'post') {
          this.dialogTitle = '新增'
          if (this.formData.gridIdArr) {
            let arr = this.formData.gridIdArr
            this.formData = {}
            this.$set(this.formData, 'gridIdArr', arr)
          } else {
            this.formData = {}
          }
        } else {
          let obj = {}
          obj = JSON.stringify(callbackData.rows[0])
          this.formData = JSON.parse(obj)
          let regionData = {}
          regionData.id = this.formData.gridId
          regionData.items = this.treeData
          let gridIdArr = getAllRegion(regionData)
          this.$set(this.formData, 'gridIdArr', gridIdArr)
        }
        this.showOnly = callbackData.sohwOnly
        this.dialogTitle = callbackData.dialogTitle
        this.dialogFormVisible = true
      }
    },
    handleCheckedRows (rows) {
      if (rows && rows instanceof Array && rows.length > 0) {
        this.currentSelectedData = rows
        this.formData = rows[0]
      } else if (rows.length === 0) {
        this.currentSelectedData = []
      }
    },
    appTreeClick (data) {
      let gridData = {}
      gridData.id = data.id
      gridData.items = this.treeData
      let gridIdArr = getAllRegion(gridData)
      this.$set(this.formData, 'gridIdArr', gridIdArr)
      this.selectForm.gridId = data.id
      this.selectForm.offset = 0
      this.getTableData(this.selectForm)
    },
    searchHandleClick () {
      this.selectForm.offset = 0
      this.getTableData(this.selectForm)
    }
  }
}
</script>
